 <template>
  <div>
    <div class="bot">
      <ul class="bot-left">
        <li @click="pi = ''">全部分类</li>
        <li v-for="i in arr" @click="cha(i.id)">{{ i.name }}</li>
      </ul>
      <div class="bot-right">
        <div class="b-tp">
          <div
            class="b-p" 
            v-for="item in arrnew"
            v-if="pi == '' || item.pid == pi"
          >
            <img :src="item.icon" alt="" />
            <p>{{ item.name }}</p>
          </div>
        </div>
      </div>
      <router-link to="Tz" replace> 跳转 </router-link>
    </div>
  </div>
</template>
 <script>
export default {
  data() {
    return {
      arr: [],
      arrnew: [],
      pi: "",
    };
  },
  methods: {
    cha(id) {
      this.pi = id;
      console.log(Number(null));
      var str1 = new RegExp("e");
      document.write(str1.exec("hello"));
    },
  },
  mounted() {
    this.axios
      .get("https://api.it120.cc/small4/shop/goods/category/all")
      .then((res) => {
        res.data.data.forEach((item) => {
          this.arrnew.push(item);
          if (item.level == 1) {
            this.arr.push(item);
            console.log(item.id);

          }
        });
      });
  },
  computed: {},
};
</script>
 <style lang='css'>
.active {
  color: red;
}
* {
  margin: 0;
  padding: 0;
}
.bot {
  width: 100%;
  overflow-y: auto;
  display: flex;
  justify-content: space-between;
}
.bot-left {
  width: 6rem;
  height: 25rem;
  border: 1px solid #000;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bot-left li {
  list-style: none;
  margin-top: 30px;
}
.bot-right {
  flex: 1;
}
.b-tp {
  width: 100%;
  height: 8rem;
  display: flex;
  flex-wrap: wrap;
}
.b-p {
  width: 30%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.b-p img {
  width: 100%;
  height: 6rem;
}
</style>